home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / basewnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  17.6 KB  |  543 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. //NONPORTABLE
  30. #ifndef _BASEWND_H
  31. #define _BASEWND_H
  32.  
  33. #define WIN32_LEAN_AND_MEAN
  34. #include "std.h"
  35. #include "common.h"
  36. #include "rootwnd.h"
  37. #include "drag.h"
  38. #include "ptrlist.h"
  39. #include "tlist.h"
  40. #include "named.h"
  41.  
  42. class BaseWnd;
  43. class TipWnd;
  44. class BltCanvas;
  45. class FilenamePS;
  46. class Canvas;
  47. class CanvasBase;
  48. class Region;
  49. class DragSet;
  50. class VirtualWnd;
  51.  
  52. using namespace wasabi;
  53.  
  54. // it is safe to use anything higher than this for your own funky messages
  55. #define BASEWND_NOTIFY_USER    NUM_NOTIFY_MESSAGES
  56.  
  57. #define BASEWND_CURSOR_USERSET            -1// window will do own setting
  58. #define BASEWND_CURSOR_POINTER            1
  59. #define BASEWND_CURSOR_NORTHSOUTH        2
  60. #define BASEWND_CURSOR_EASTWEST            3
  61. #define BASEWND_CURSOR_NORTHWEST_SOUTHEAST    4
  62. #define BASEWND_CURSOR_NORTHEAST_SOUTHWEST    5
  63. #define BASEWND_CURSOR_4WAY            6
  64.  
  65. // Our own defined window messages
  66.  
  67. #define WM_WA_CONTAINER_TOGGLED WM_USER+0x1338
  68. #define WM_WA_COMPONENT_TOGGLED WM_USER+0x1339
  69. #define WM_WA_RELOAD            WM_USER+0x133A
  70. #define WM_WA_GETFBSIZE         WM_USER+0x133B
  71. #define WM_WA_CONTEXTMENUNOTIFY WM_USER+0x133D
  72. #define WM_WA_ACTIONNOTIFY      WM_USER+0x133E
  73.  
  74. #define DEFERREDCB_FLUSHPAINT   0x200
  75.  
  76. #define SYSRGN  4
  77.  
  78. typedef struct {
  79.   RootWnd *origin;
  80.   int param1;
  81.   int param2;
  82. } defered_callback;
  83.  
  84. // base class
  85. #define BASEWND_PARENT RootWndI
  86. class COMEXP NOVTABLE BaseWnd :
  87.   public RootWndI,
  88.   public DragInterface,
  89.   public Named {
  90.  
  91.   friend VirtualWnd;
  92.  
  93. protected:
  94.   // override constructor to init your data, but don't create anything yet
  95.   BaseWnd();
  96. public:
  97.   virtual ~BaseWnd();
  98.  
  99. //INITIALIZATION
  100.   // these actually create the window
  101.   // try REALLY hard to not have to override these, and if you do,
  102.   // override the second one
  103.   virtual int init(RootWnd *parent, int nochild=FALSE);
  104.   virtual int init(HINSTANCE hInstance, HWND parent, int nochild=FALSE);// for the root window
  105.   virtual int isInited();    // are we post init() ? USE THIS INSTEAD OF gethWnd()==1
  106.  
  107.   // if at all possible put your init stuff in this one, and call up the
  108.   // heirarchy BEFORE your code
  109.   virtual int onInit();
  110.  
  111.   // use this to return the cursor type to show
  112.   virtual int getCursorType(int x, int y);
  113.  
  114. // WINDOW SIZING/MOVEMENT/CONTROL
  115.   virtual int getFontSize() { return 0; }
  116.   virtual int setFontSize(int size) { return -1; }
  117.  
  118.   // if you override it, be sure to call up the heirarchy
  119.   virtual void resize(int x, int y, int w, int h);    // resize yourself
  120.   void resize(RECT *r);
  121.   void resizeToRect(RECT *r) { resize(r); }//helper
  122.  
  123.   // called after resize happens, return TRUE if you override
  124.   virtual int onResize();
  125.   void resizeToClient(BaseWnd *wnd);    // resize a window to match you
  126.   virtual int onPostedMove(); // whenever WM_WINDOWPOSCHANGED happens, use mainly to record positions when moved by the window tracker, avoid using for another prupose, not portable
  127.  
  128.   // move only, no resize
  129.   virtual void move(int x, int y);
  130.  
  131.   // puts window on top of its siblings
  132.   virtual void moveToFront();
  133.   // puts window behind its siblings
  134.   virtual void moveToBack();
  135.  
  136.   // fired when a sibbling invalidates a region. you can change the region before returning, use with care, can fuck up everything if not used well
  137.   virtual int onSiblingInvalidateRgn(Region *r, RootWnd *who, int who_idx, int my_idx) { return 0; }
  138.  
  139.   // set window's visibility
  140.   virtual void setVisible(int show);
  141.   virtual void onSetVisible(int show);    // override this one
  142.  
  143.   // enable/disable window for input
  144.   virtual void enable(int en);
  145.   // grab the keyboard focus
  146.   virtual void setFocus();
  147.  
  148.   virtual int pointInWnd(POINT *p);
  149.  
  150.   // repaint yourself
  151.   virtual void invalidate();    // mark entire window for repainting
  152.   virtual void invalidateRect(RECT *r);// mark specific rect for repainting
  153.   virtual void invalidateRgn(Region *r);// mark specific rgn for repainting
  154.   virtual void invalidateFrom(RootWnd *who);    // mark entire window for repainting
  155.   virtual void invalidateRectFrom(RECT *r, RootWnd *who);// mark specific rect for repainting
  156.   virtual void invalidateRgnFrom(Region *r, RootWnd *who);// mark specific rgn for repainting
  157.   virtual void validate(); // unmark the entire window from repainting
  158.   virtual void validateRect(RECT *r); // unmark specific rect from repainting
  159.   virtual void validateRgn(Region *reg); // unmark specific region from repainting
  160.  
  161.   // no virtual on these please
  162.   void deferedInvalidateRgn(Region *h);
  163.   void deferedInvalidateRect(RECT *r);
  164.   void deferedInvalidate();
  165.   void deferedValidateRgn(Region *h); 
  166.   void deferedValidateRect(RECT *r);
  167.   void deferedValidate();
  168.   Region *getDeferedInvalidRgn();
  169.   int hasVirtualChildren();
  170.   virtual int focusNextSibbling(int dochild);
  171.   virtual int focusNextVirtualChild(BaseWnd *child);
  172.   virtual int focusVirtualChild(RootWnd *child);
  173.  
  174. private: 
  175.   virtual void physicalInvalidateRgn(Region *r); 
  176. protected:
  177.   virtual int ensureVirtualCanvasOk();
  178.   virtual void setVirtualCanvas(Canvas *c);
  179.   virtual void setRSize(int x, int y, int w, int h);
  180.  
  181. public:
  182.  
  183.   virtual void repaint();    // repaint right now!
  184.  
  185.   // override this to add decorations
  186.   virtual void getClientRect(RECT *);
  187.   RECT clientRect();    // helper
  188.   virtual void getNonClientRect(RECT *);
  189.   RECT nonClientRect();    // helper
  190.   virtual void getWindowRect(RECT *);    // windows coords in screen system
  191.   RECT windowRect();    // helper
  192.  
  193.   virtual void clientToScreen(int *x, int *y);        // convenience fn
  194.   virtual void screenToClient(int *x, int *y);        // convenience fn
  195.   virtual void clientToScreen(POINT *pt);        // convenience fn
  196.   virtual void screenToClient(POINT *pt);        // convenience fn
  197.   virtual void clientToScreen(RECT *r);        // convenience fn
  198.   virtual void screenToClient(RECT *r);        // convenience fn
  199.  
  200.   void setIcon(HICON icon, int _small);
  201.   virtual void setSkinId(int id);
  202.  
  203.   virtual int getPreferences(int what);
  204.   virtual void setStartHidden(int wtf);
  205.  
  206. // from RootWnd
  207. protected:
  208.   virtual DragInterface *getDragInterface();
  209.   virtual RootWnd *rootWndFromPoint(POINT *pt);
  210.   virtual int getSkinId();
  211.   virtual int onMetricChange(int metricid, int param1, int param2);
  212.   virtual int rootwnd_onPaint(CanvasBase *canvas, Region *r);
  213.   virtual int rootwnd_paintTree(CanvasBase *canvas, Region *r);
  214.  
  215. public:
  216. #ifdef WIN32
  217.   // override for custom processing (NONPORTABLE!)
  218.   virtual LRESULT wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  219. #endif
  220. // end from RootWnd
  221.  
  222.   // or override these, they're more portable
  223.   virtual int onContextMenu(int x, int y);    // always return 1 if accept msg
  224.   virtual int onChildContextMenu(int x, int y);    // always return 1 if accept msg
  225.  
  226.   void postDeferredCallback(int param1, int param2);
  227.   virtual int onDeferredCallback(int param1, int param2);
  228.  
  229.   // called on WM_PAINT by onPaint(Canvas, Region *), if the canvas is null, create your own, if not, it will have update regions clipped for you
  230.   virtual int onPaint(Canvas *canvas);
  231.   void setTransparency(int amount);    // 0..255
  232.  
  233. private:
  234.   virtual int onPaint(Canvas *canvas, Region *r);
  235.  
  236. public:  
  237.   // click-drag. FYI, the drag-drop handling overrides these
  238.   virtual int onLeftButtonDown(int x, int y); 
  239.   virtual int onRightButtonDown(int x, int y) { return 0; }
  240.   virtual int onMouseMove(int x, int y);    // only called when mouse captured
  241.   virtual int onLeftButtonUp(int x, int y) { return 0; }
  242.   virtual int onRightButtonUp(int x, int y) { return 0; }
  243.   virtual int onMouseWheelUp(int click, int lines);
  244.   virtual int onMouseWheelDown(int click, int lines);
  245.   virtual int beginCapture();
  246.   virtual int endCapture();
  247.   virtual int getCapture();    // returns 1 if this window has mouse/keyb captured
  248.  
  249.   // these will not be called in the middle of a drag operation
  250.   virtual int onLeftButtonDblClk(int x, int y);
  251.   virtual int onRightButtonDblClk(int x, int y);
  252.  
  253.   virtual int onGetFocus();    // you have the keyboard focus
  254.   virtual int onKillFocus();    // you lost the keyboard focus
  255.   virtual int gotFocus();
  256.   // return 1 if your derived class can indicate it has focus (i.e. LabelWnd)
  257.   virtual int canShowFocus() { return 0; }
  258.   int isActive();
  259.   virtual int onActivate();
  260.   virtual int onDeactivate();
  261.   virtual int onEnable(int en);
  262.   virtual int getEnabled();
  263.  
  264.   virtual int onChar(char c);
  265.   virtual int onKeyDown(int keyCode) { return 0; }
  266.   virtual int onKeyUp(int keyCode) { return 0; }
  267.  
  268.   virtual int onContextMenuNotify(int action, int param=0) { return 0; }
  269.   virtual int onActionNotify(int action, int param=0) { return 0; }
  270.  
  271.   virtual int onEraseBkgnd(HDC dc);// override and return 0 to authorize bkg painting, 1 to avoid it (default to 1)
  272.   virtual int onUserMessage(int msg, int w, int l, int *r);
  273.  
  274. //CHILD->PARENT MESSAGES
  275.   // feel free to override for your own messages, but be sure to call up the
  276.   // chain for unhandled msgs
  277.   // children should not call this directly if they don't have to; use
  278.   // notifyParent on yourself instead
  279.   // message ids should be put in notifmsg.h to avoid conflicts
  280.   virtual int childNotify(RootWnd *child, int msg,
  281.                           int param1=0, int param2=0);
  282.  
  283.   // don't try to override these
  284.   void setParent(RootWnd *newparent);
  285.   RootWnd *getParent();
  286.   virtual RootWnd *getRootParent(); 
  287.   
  288.   // avoid overriding this one if you can
  289.   virtual int reparent(RootWnd *newparent);
  290.  
  291.   // override this one
  292.   virtual void onSetParent(RootWnd *newparent) {}
  293.  
  294.   // override this to do your own region checking
  295.   virtual BOOL mouseInRegion(int x, int y) { return 1; }
  296.  
  297.   // call this to notify your parent via its childNotify method
  298.   virtual int notifyParent(int msg, int param1=0, int param2=0);
  299.  
  300.   // from class Named
  301.   virtual void onSetName();
  302.  
  303.   virtual const char *getTip();
  304.   virtual void setTip(const char *tooltip);
  305.   virtual int getStartHidden();
  306.   virtual void abortTip();
  307.   virtual int isVisible();
  308.  
  309.     // Virtual windows functions
  310.   virtual Canvas *createFrameBuffer(int w, int h);
  311.   virtual void prepareFrameBuffer(Canvas *canvas, int w, int h);
  312.   virtual void deleteFrameBuffer(Canvas *canvas);
  313.  
  314.   virtual void addVirtualChild(RootWnd *child);
  315.   virtual void removeVirtualChild(RootWnd *child);
  316.   virtual int isVirtual();
  317.   static RootWnd *checkGhost(RootWnd *r, short x, short y);
  318.   virtual RootWnd *getVirtualChild(int x, int y);
  319.   virtual RootWnd *getVirtualChild(int _enum);
  320.   virtual int getNumVirtuals();
  321.   virtual int handleVirtualChildMsg(UINT uMsg,int x, int y, void *p=NULL);
  322.   virtual void setVirtualChildCapture(RootWnd *child);
  323.   virtual RootWnd *getVirtualChildCapture();
  324.   virtual int setVirtualChildTimer(RootWnd *child, int id, int ms);
  325.   virtual int killVirtualChildTimer(RootWnd *child, int id);
  326.  
  327.   virtual int cascadeRepaintFrom(RootWnd *who);
  328.   virtual int cascadeRepaintRgnFrom(Region *reg, RootWnd *who);
  329.   virtual int cascadeRepaintRectFrom(RECT *r, RootWnd *who);
  330.   virtual int cascadeRepaint();
  331.   virtual int cascadeRepaintRgn(Region *reg);
  332.   virtual int cascadeRepaintRect(RECT *r);
  333.   virtual void flushPaint();
  334.  
  335.   virtual void freeResources();
  336.   virtual void reloadResources();
  337.  
  338. protected:
  339.   virtual void do_flushPaint();
  340.   virtual int paintTree(Canvas *canvas, Region *r);
  341.   virtual int virtualBeforePaint() { return 0; }
  342.   virtual int virtualAfterPaint() { return 0; }
  343.   virtual int virtualOnPaint();
  344.   virtual void virtualCanvasCommit(Canvas *canvas, RECT *r, double ratio);
  345.  
  346. public:
  347.     
  348. #ifdef WIN32
  349.   virtual HWND gethWnd();
  350.   //NONPORTABLE--avoid prolonged use
  351.   virtual HINSTANCE gethInstance();//FUCKO CUT, use HINSTANCEfromHWND
  352. #endif
  353.  
  354. public:
  355.     
  356.   BOOL getNoCopyBits(void);
  357.   void setNoCopyBits(BOOL ncb);
  358.  
  359. protected:
  360. //TIMERS
  361.   // portable helper timer fns
  362.   virtual int setTimer(int id, int ms);
  363.   virtual void timerCallback(int id);
  364.   virtual int killTimer(int id);
  365.   virtual int checkDoubleClick(int button, int x, int y);
  366.  
  367. //MISC
  368. public:
  369.   virtual int isDestroying();    // in the middle of dying
  370.  
  371. //DRAGGING AND DROPPING -- (derived from DragInterface)
  372.  
  373.   // derived windows should call this if they detect a drag beginning
  374.   // call once per datum per type of data being exposed. order is maintained
  375.   int addDragItem(char *droptype, void *item);
  376.   // returns TRUE if drop was accepted
  377.   int handleDrag();
  378.   int resetDragSet();    // you don't need to call this
  379.  
  380.   // (called on dest) when dragged item enters the winder
  381.   virtual int dragEnter(RootWnd *sourceWnd);
  382.   // (called on dest) during the winder
  383.   // FG> x/y are in screen corrdinates because target is a rootwnd
  384.   virtual int dragOver(int x, int y, RootWnd *sourceWnd) { return 0; }
  385.   // (called on src)
  386.   virtual int dragSetSticky(RootWnd *wnd, int left, int right, int up, int down);
  387.   // (called on dest) when dragged item leaves the winder
  388.   virtual int dragLeave(RootWnd *sourceWnd) { return 0; }
  389.  
  390.   // when it finally is dropped:
  391.  
  392.   // called on destination window
  393.   // FG> x/y are in screen corrdinates because target is a rootwnd
  394.   virtual int dragDrop(RootWnd *sourceWnd, int x, int y) { return 0; }
  395.   // called on source window
  396.   virtual int dragComplete(int success) { return 0; }
  397.   // in that order
  398.   // must be called right before handleDrag();        (sender)
  399.   void setSuggestedDropTitle(const char *title);
  400.  
  401.   // must be called from dragDrop();            (receiver)
  402.   virtual const char *dragGetSuggestedDropTitle(void);
  403.   virtual int dragCheckData(const char *type, int *nitems=NULL);
  404.   virtual void *dragGetData(int slot, int itemnum);
  405.   virtual int dragCheckOption(int option) { return 0; }
  406.  
  407.   // return TRUE if you support any of the datatypes this window is exposing
  408.   virtual int checkDragTypes(RootWnd *sourceWnd) { return 0; }
  409.  
  410. // external drops 
  411.   // override this and return 1 to receive drops from the OS
  412.   virtual int acceptExternalDrops() { return 0; }
  413.  
  414.   virtual void onExternalDropBegin() {}
  415.   virtual void onExternalDropDirScan(const char *dirname) {}
  416.   virtual void onExternalDropEnd() {}
  417. private:
  418.   void addDroppedFile(const char *filename, PtrList<FilenamePS> *plist); // recursive
  419.  
  420. public:
  421. //FG> alternate notify window
  422.   virtual void setNotifyWindow(RootWnd *newnotify);
  423.   virtual RootWnd *getNotifyWindow();
  424.  
  425.   virtual double getRenderRatio();
  426.   virtual void setRenderRatio(double r);
  427.   virtual int handleRatio() { return 1; }
  428.   int renderRatioActive();
  429.   void multRatio(int *x, int *y=NULL);
  430.   void multRatio(RECT *r);
  431.   void divRatio(int *x, int *y=NULL);
  432.   void divRatio(RECT *r);
  433.   virtual int isClickThrough() { return 0; }
  434.  
  435. // DERIVED WINDOW BEHAVIORAL PREFERENCES
  436. protected:
  437.   virtual int wantDoubleClicks();
  438.   // return 1 to get onMouseOver even if mouse isn't captured
  439.   virtual int wantSiblingInvalidations();
  440.  
  441.   virtual int wantFocus();
  442.  
  443. protected: // tip function
  444.  
  445.   void onTipMouseMove();
  446.   void renderBaseTexture(CanvasBase *c, RECT &r);
  447.  
  448. public:
  449.   virtual RootWnd *getBaseTextureWindow();
  450.   void setBaseTextureWindow(RootWnd *w);
  451.   virtual int isMouseOver(int x, int y);
  452.  
  453.   virtual void bringVirtualToFront(RootWnd *w);
  454.   virtual void bringVirtualToBack(RootWnd *w);
  455.   virtual void bringVirtualAbove(RootWnd *w, RootWnd *b);
  456.   virtual void bringVirtualBelow(RootWnd *w, RootWnd *b);
  457.   void changeChildZorder(RootWnd *w, int newpos);
  458.  
  459. private:
  460.   // ATTENTION: note the capitalization on these -- so as not to mix up with
  461.   // wndProc()'s hWnd
  462.   HINSTANCE hinstance;
  463.   HWND hwnd;
  464.  
  465.   RootWnd *parentWnd;
  466.  
  467.   int inputCaptured;
  468.  
  469.   void onTab();
  470.  
  471. protected:
  472.  
  473.   int checkModal();
  474.  
  475.   int dragging;
  476.  
  477.     Canvas *virtualCanvas;
  478.   static int (WINAPI *getRandomRgn)(HDC dc, HRGN rgn, int i);
  479.  
  480. private:
  481.  
  482.   PtrList<DragSet> dragsets;
  483.   RootWnd *prevtarg;
  484.   String suggestedTitle;
  485.  
  486.   //FG
  487.   int start_hidden;
  488.   char *tip;
  489.   TipWnd *ttip;
  490.   BOOL tip_done;
  491.   BOOL tipawaytimer;
  492.   BOOL tipshowtimer;
  493.   BOOL tipbeenchecked;
  494.   BOOL tipdestroytimer;
  495.  
  496.   //FG
  497.   BOOL ncb;
  498.   DWORD lastClick[2];
  499.   POINT lastClickP[2];
  500.  
  501.   //FG
  502.   RootWnd *btexture;
  503.  
  504.   //FG
  505.   RootWnd *notifyWindow;
  506.   BOOL destroying;
  507.  
  508.     //CT:Virtual children
  509.     PtrList<RootWnd> virtualChildren;
  510.     int virtualCanvasHandled;
  511.     int virtualCanvasH,virtualCanvasW;
  512.     int rwidth, rheight, rx, ry;
  513.     RootWnd *curVirtualChildCaptured;
  514.     typedef struct {
  515.         int id;
  516.         RootWnd *child;
  517.     } virtualChildTimer;
  518.     wasabi::TList<virtualChildTimer> virtualChildTimers;
  519.  
  520.     //FG>
  521.     Region *deferedInvalidRgn;
  522.     static int nreal;
  523.     static HINSTANCE gdi32instance;
  524.   static int grrfailed;
  525.  
  526.   HWND oldCapture;
  527.   
  528.     int hasfocus;
  529.     BaseWnd *curVirtualChildFocus;
  530.  
  531.     double ratio;
  532.   int skin_id;
  533. };
  534.  
  535. #ifdef WIN32
  536. __inline HINSTANCE HINSTANCEfromHWND(HWND wnd) {
  537.   if (wnd == NULL) return NULL;
  538.   return (HINSTANCE)GetWindowLong(wnd, GWL_HINSTANCE);
  539. }
  540. #endif
  541.  
  542. #endif
  543.